/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */
import { ModuleModel } from '../../model/module/module-model.js';
import { ExternalNativeOpt } from '../../options/build/build-opt.js';
import { BuildOpt } from '../../options/build/build-opt.js';

export enum ArtifactType {
  ORIGINAL = 'original',
  OBFUSCATION = 'obfuscation',
  BYTECODE = 'bytecode',
}

export class HarExtendInfo {
  private readonly moduleModel: ModuleModel;
  readonly artifactType: string | undefined;
  readonly nativeOption?: ExternalNativeOpt;
  readonly buildOpt: BuildOpt;

  constructor(moduleModel: ModuleModel, buildOption: BuildOpt) {
    this.moduleModel = moduleModel;
    this.artifactType = buildOption.artifactType;
    this.nativeOption = buildOption.externalNativeOptions;
    this.buildOpt = buildOption;
  }

  hasConfiguredNativeOption(): boolean {
    return this.nativeOption !== undefined;
  }

  isObfuscatedHar(): boolean {
    if (this.buildOpt.debuggable) {
      return false;
    }
    const enableObfuscation: boolean | undefined = this.buildOpt.arkOptions?.obfuscation?.ruleOptions?.enable;
    return enableObfuscation || (enableObfuscation === undefined && this.artifactType === ArtifactType.OBFUSCATION);
  }

  getArtifactType(): string {
    return this.artifactType === undefined ? ArtifactType.ORIGINAL : this.artifactType;
  }
}
